package tweeks.common.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class AuthorityController {
	
	@RequestMapping(method=RequestMethod.POST, value="/main/isGranted")
	public void isGranted(HttpServletRequest request, HttpServletResponse response) throws IOException {
		Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		String message = principal instanceof UserDetails ? "success" : "failure";
		response.getWriter().print(message);
        response.getWriter().flush();
	}
}
